/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package assignment2.stub;

import assignment2.data.Users;
import assignment2.data.UsersFacade;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author tuan
 */
public class UsersTbl_Stub {
    
    UsersFacade usersFacade = lookupUsersFacadeBean();
    
    public boolean checkLogin(String username, String password) {
        return usersFacade.checkLogin(username, password);
        
    }
    
    public void insert(Users user) {
        usersFacade.create(user);
    }
   
    public Users searchByUserName(String username) {
        return usersFacade.find(username);
    }
    
    public List<Users> listAll() {
        return usersFacade.findAll();
    }
    
    public void removeUsers(String userName) {
        Users user = usersFacade.find(userName);
        usersFacade.remove(user);
        
    }

    public void modify(Users user) {
        usersFacade.edit(user);
    }
    public boolean changePassword(Users user){
       if(user != null){
       usersFacade.edit(user);
       return true;
       }
       return false;
    }
    
    private UsersFacade lookupUsersFacadeBean() {
        try {
            Context c = new InitialContext();
            return (UsersFacade) c.lookup("java:global/Assignment2/Assignment2-ejb/UsersFacade!assignment2.data.UsersFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }
}
